<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="jquery-1.4.4.min.js"></script>
    <script src="jsencrypt.min.js"></script>

</head>
<body>
<div>
    <input type="text" placeholder="用户名" id="userName">
    <input type="password" placeholder="密码" id="userPsd">
    <input type="button" value="登录" id="login_bt">
</div>
</body>
<script>

    var public_key=''
    //获取公钥
    $.ajax({
        type:'get',
        url:'/index',
        data:{},
        success:function(date){
            public_key = date;
            console.log(date,date)
        }
    })
    console.log("public_key:"+public_key)
$('#login_bt').click(function (e) {

    var userName=$('#userName').val()
    var userPsd=$('#userPsd').val()

    //对密码进行加密
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(public_key);
    $.ajax({
        type:'get',
        url:'/login',
        data:{
            userName:encrypt.encrypt(userName),
            userPsd:encrypt.encrypt(userPsd)
        },
        success:function(date){
            console.log('test success!')
        }
    })

})
</script>
</html>